package corp.edu.amadeus.core.dao.impl;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.type.Type;

public class Parameter {

    private Type type;

    private String name;

    private Object value;

    public Parameter(String name, Object value, Type type) {
        this.type = type;
        this.name = name;
        this.value = value;
    }

    public Parameter(String name, Object value) {
        this.name = name;
        this.value = value;
    }

    public void addToQuery(Query query) throws HibernateException {
        if (type == null) {
            query.setParameter(name, value);
        } else {
            query.setParameter(name, value, type);
        }
    }

}
